package com.mlnx.web.ui.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.mlnx.common.entity.Response;
import com.mlnx.ui.entity.HealthReport;
import com.mlnx.ui.pojo.form.HealthReportForm;
import com.mlnx.ui.pojo.vo.SportWayVO;
import com.mlnx.ui.service.HealthReportService;
import com.mlnx.ui.service.SportWayService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.shan.spring.base.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "UI康复运动接口", tags = "UI康复运动接口")
@RestController
@RequestMapping("ui/rehabilitation")
public class RehabilitationController extends BaseController {
    @Autowired
    private HealthReportService healthReportService;

    @Autowired
    private SportWayService sportWayService;


    @ApiOperation("保存康复运动报告")
    @PostMapping(value = "/report")
    public Response saveHealthReport(@RequestBody HealthReportForm healthReportForm) {
        healthReportService.saveHealthReport(healthReportForm);

        return result();
    }


    @ApiOperation("保存康复运动特征心电时间段")
    @PutMapping(value = "/report/{id}")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "ecgRecord", value = "心电时间段", required = true)
    })
    public Response setEcgMarks(@RequestParam("ecgRecord") String ecgRecord,
                                @PathVariable("id") Integer id) {
        HealthReport healthReport = new HealthReport();
        healthReport.setId(id);
        healthReport.setEcgRecord(ecgRecord);

        healthReportService.updateById(healthReport);

        return result();
    }

    @ApiOperation("通过患者ID获取康复运动报告列表")
    @GetMapping(value = "/report")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "patientId", value = "患者ID", required = true)
    })
    public Response getRehabilitationRecords(@RequestParam Integer patientId) {
        List<HealthReport> healthReports = healthReportService.list(new QueryWrapper<HealthReport>().eq("patientId", patientId));

        return result(healthReports);
    }

    @ApiOperation("通过报告ID获得康复运动报告")
    @GetMapping(value = "/report/{id}")
    public Response getHealthReport(@PathVariable("id") Integer id) {
        healthReportService.getById(id);

        return result();
    }


    @ApiOperation("保存运动处方")
    @PostMapping(value = "/prescription")
    public Response saveSportWay(@RequestBody SportWayVO sportWayVO) {
        sportWayService.saveSportPrescription(sportWayVO);

        return result();
    }

    @ApiOperation("通过患者ID获得运动处方列表")
    @GetMapping(value = "/prescription")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "patientId", value = "患者ID", required = true)
    })
    public Response getSportWay(@RequestParam("patientId") Integer patientId) {
        List<SportWayVO> sportPrescriptions = sportWayService.getSportPrescriptions(patientId);

        return result(sportPrescriptions);
    }
}
